<template>
	<view class="container">
		<!-- 小程序头部兼容 -->
		<!-- #ifdef MP -->
		<!-- <view class="mp-search-box" @click="toSearch">
			<input class="ser-input" type="text" placeholder="请输入搜索的内容" disabled />
		</view> -->
		<!-- #endif -->


		<!-- <view class="mp-search-box" @click="toSearch">
			<input class="ser-input" type="text" placeholder="请输入搜索的内容" disabled />
		</view> -->


		<view class="background">
			<view class="home">
				<u-search inputAlign="center" placeholder="请输入关键词搜索" shape="round" :show-action="false" :disabled="true"
					@click="toSearch"></u-search>
			</view>
		</view>

		<view style="width: 100%;height: 200upx;border-bottom-left-radius: 40upx;border-bottom-right-radius: 40upx;
		background-color: #F8D55D;">

		</view>

		<!-- 头部轮播 -->
		<view class="carousel-section"
			style="margin-top: -190upx;margin-left: 20upx;margin-right: 20upx;border-radius: 30upx;">
			<view class="titleNview-placing"></view>
			<swiper class="carousel" circular>
				<swiper-item v-for="(item, index) in bannerList" :key="index" class="carousel-item"
					@click="navToDetailPage(item.id)">
					<image :src="item.imageUrl" />
				</swiper-item>
			</swiper>
			<view class="swiper-dots">
				<text class="num">{{swiperCurrent+1}}</text>
				<text class="sign">/</text>
				<text class="num">{{swiperLength}}</text>
			</view>
		</view>




		<view class="home u-p-b-0">
			<view style="position: relative;background: rgba(255,255,255,0.8);height: 80upx;
		margin-right: 12upx;border-radius: 24upx;margin-top: 16upx;margin-left: 12upx;box-shadow: 2rpx 2rpx 3rpx #aaaaaa;">
				<image class="notify-icon" src="../../static/notify2.png"
					style="position: absolute;left: 1%;margin-top: 20upx;" mode=""></image>
				<view style="margin-left: 80upx;">
					<swiper style="height: 80upx;" :autoplay="true" :interval="3000" :duration="1000"
						:disable-touch="false" :touchable="false" :circular="true" :vertical="true">
						<swiper-item v-for="(item,index) in notifyList" :key="index" @touchmove.stop="true">
							<view class="swiper-item" style="color: #444444;font-size: 28upx;line-height: 80upx;"><text
									style="font-weight: bold;">公告</text> <text
									style="margin-left: 10upx;">{{item}}</text> </view>
						</swiper-item>

					</swiper>
				</view>

			</view>

		</view>
		<!-- 秒杀楼层 -->


		<view class="pop-window-wrapper" style="box-shadow: 5rpx 5rpx 3rpx #aaaaaa;">
			<view class="pop-window-in-wrapper" @click="toCategory(1)">
				<image class="pop-window-img" src="../../static/images/mini-logo.png" mode=""></image>
				<view class="pop-title">小程序</view>
			</view>
			<view class="pop-window-in-wrapper" @click="toCategory(2)">
				<image class="pop-window-img" src="../../static/images/web.png" mode=""></image>
				<view class="pop-title">网站源码</view>
			</view>

			<view class="pop-window-in-wrapper" @click="toCategory(3)">
				<image class="pop-window-img" src="../../static/images/yinyong.png" mode=""></image>
				<view class="pop-title">应用源码</view>
			</view>

			<view class="pop-window-in-wrapper" @click="toPlay">
				<image class="pop-window-img" src="../../static/images/tool2.png" mode=""></image>
				<view class="pop-title">实用工具</view>
			</view>

		</view>



		<!-- 推荐资源 -->
		<view class="f-header m-t">
			<image src="/static/temp/h1.png"></image>
			<view class="tit-box">
				<text class="tit" style="font-weight: bold;">推荐资源</text>
			</view>
			<text class="yticon icon-you" @click="toCategory(1)"></text>
		</view>
		<water :list="flowList"></water>

	
	


	</view>
</template>

<script>
	import water from '../../components/water.vue';
	import {
		resource_code_page,
		resource_code_search,
		resource_code_page_not_loading
	} from '../../api/resource_code.js'
	import {
		banner_list
	} from '../../api/banner.js'
	import {
		notice_list
	} from '../../api/config.js'

	export default {
		components: {
			water
		},
		data() {
			return {
				titleNViewBackground: '',
				swiperCurrent: 0,
				swiperLength: 0,
				carouselList: [],
				notifyList: [

				],
				flowList: [],
				current: 2,
				goodsList: [],
				bannerList: []
			};
		},


		onLoad() {
			wx.showShareMenu({
					menus: ['shareAppMessage', 'shareTimeline'],// 需要显示的转发按钮名称列表.合法值包含 "shareAppMessage"、"shareTimeline"
					success(res) {
						console.log(res);
					},
					fail(e) {
						console.log(e);
					}
				});

			this.getResourcePage();
			this.getBannerList();
			this.getNoticeList();
		},
		onShow() {
			this.getResourcePageNotLoading()
		},
		onPullDownRefresh() {
			this.getResourcePage();
		},


		onReachBottom() {
			let params = {}
			params.pageSize = 10;
			params.current = this.current;
			resource_code_page(params).then(res => {
				console.log(res)
				this.flowList = this.flowList.concat(res.data)
				this.current = this.current + 1;
			})

		},
		  onShareTimeline: function() {
		    return {
		      title: '源码字节',
		      path: '/page/index/index',
		    }
		  },

		methods: {
			getNoticeList() {
				notice_list({}).then(res => {
					this.notifyList = res.data
				})
			},

			toPlay() {
				uni.switchTab({
					url: '../play/play'
				})
			},
			custom(value) {
				this.resourceList = []
				console.log(value)
				if (value === null || value === '') {
					this.resourceList = []
					uni.showToast({
						title: '请输入搜索内容',
						icon: 'none'
					})
					return
				}
				console.log(value)
				let params = {}
				params.pageSize = 10;
				params.keyword = value;
				resource_code_search(params).then(res => {
					console.log(res)
					this.resourceList = res.data
				})
			},

			search(value) {
				uni.navigateTo({
					url: '../search/search'
				})
			},

			change(value) {
				if (value !== null || value !== '') {
					this.resourceList = []
				}

			},
			toCategory(type) {
				// uni.setStorageSync('resource_type',type)
				uni.switchTab({
					url: `/pages/category/category`
				})
			},
			getBannerList() {
				let params = {}
				params.type = 1
				params.location = 1
				banner_list(params).then(res => {
					this.bannerList = res.data
					this.swiperLength = res.data.length
				})

			},
			toSearch() {
				console.log(11111111)
				uni.navigateTo({
					url: '../search/search'
				})
			},
			/**
			 * 请求静态数据只是为了代码不那么乱
			 * 分次请求未作整合
			 */
			getResourcePage() {
				let params = {}
				params.pageSize = 10;
				resource_code_page(params).then(res => {
					if (res.status !== 3001) {
						this.flowList = res.data
					} else {
						uni.navigateTo({
							url: '../login/login'
						})
					}

				})
			},
			getResourcePageNotLoading() {
				let params = {}
				params.pageSize = 10;
				resource_code_page_not_loading(params).then(res => {
					console.log(res)
					if (res.status !== 3001) {
						this.flowList = res.data
					} else {
						uni.navigateTo({
							url: '../login/login'
						})
					}
				})
			},
			//轮播图切换修改背景色
			swiperChange(e) {
				const index = e.detail.current;
				this.swiperCurrent = index;
				this.titleNViewBackground = this.carouselList[index].background;
			},
			//详情页
			navToDetailPage(id) {
				//测试数据没有写id，用title代替
				uni.navigateTo({
					url: `/pages/product/product?id=${id}`
				})
			},
		},
		// #ifndef MP
		// 标题栏input搜索框点击
		onNavigationBarSearchInputClicked: async function(e) {
			this.$api.msg('点击了搜索框');
		},
		//点击导航栏 buttons 时触发
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				this.$api.msg('点击了扫描');
			} else if (index === 1) {
				// #ifdef APP-PLUS
				const pages = getCurrentPages();
				const page = pages[pages.length - 1];
				const currentWebview = page.$getAppWebview();
				currentWebview.hideTitleNViewButtonRedDot({
					index
				});
				// #endif
				uni.navigateTo({
					url: '/pages/notice/notice'
				})
			}
		}
		// #endif
	}
</script>

<style lang="scss">
	/* #ifdef MP */
	.mp-search-box {
		position: absolute;
		left: 0;
		top: 30rpx;
		z-index: 9999;
		width: 100%;
		padding: 0 40rpx;

		.ser-input {
			flex: 1;
			height: 56rpx;
			line-height: 56rpx;
			text-align: center;
			font-size: 28rpx;
			color: $font-color-base;
			border-radius: 20px;
			background: rgba(255, 255, 255, 0.15);
			// background-color: transparent;
		}
	}

	.background {
		background-image: linear-gradient(45deg, rgb(248, 213, 93), rgb(248, 213, 93));
	}

	page {
		.cate-section {
			position: relative;
			z-index: 5;
			border-radius: 16rpx 16rpx 0 0;
			margin-top: -20rpx;
		}

		.carousel-section {
			padding: 0;

			.titleNview-placing {
				padding-top: 0;
				height: 0;
			}

			.carousel {
				.carousel-item {
					padding: 0;
				}
			}

			.swiper-dots {
				// right:45rpx;
				bottom: 40rpx;
			}
		}
	}

	/* #endif */


	page {
		background: #f5f5f5;
	}

	.notify-icon {
		width: 40upx;
		height: 40upx;
		margin-left: 24upx;
	}

	.m-t {
		margin-top: 16rpx;
	}

	/* 头部 轮播图 */
	.carousel-section {
		position: relative;
		padding-top: 10px;

		.titleNview-placing {
			height: var(--status-bar-height);
			padding-top: 44px;
			box-sizing: content-box;
		}

		.titleNview-background {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 426rpx;
			transition: .4s;
		}
	}

	.carousel {
		width: 100%;
		height: 350rpx;

		.carousel-item {
			width: 100%;
			height: 100%;
			padding: 0 28rpx;
			overflow: hidden;
		}

		image {
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}
	}

	.swiper-dots {
		display: flex;
		position: absolute;
		right: 60rpx;
		bottom: 15rpx;
		width: 72rpx;
		height: 36rpx;
		background-image: url();
		background-size: 100% 100%;

		.num {
			width: 36rpx;
			height: 36rpx;
			border-radius: 50px;
			font-size: 24rpx;
			color: #fff;
			text-align: center;
			line-height: 36rpx;
		}

		.sign {
			position: absolute;
			top: 0;
			left: 50%;
			line-height: 36rpx;
			font-size: 12rpx;
			color: #fff;
			transform: translateX(-50%);
		}
	}

	/* 分类 */
	.cate-section {
		display: flex;
		justify-content: space-around;
		align-items: center;
		flex-wrap: wrap;
		padding: 30rpx 22rpx;
		background: #fff;

		.cate-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			font-size: $font-sm + 2rpx;
			color: $font-color-dark;
		}

		/* 原图标颜色太深,不想改图了,所以加了透明度 */
		image {
			width: 88rpx;
			height: 88rpx;
			margin-bottom: 14rpx;
			border-radius: 50%;
			opacity: .7;
			box-shadow: 4rpx 4rpx 20rpx rgba(250, 67, 106, 0.3);
		}
	}

	.ad-1 {
		width: 100%;
		height: 210rpx;
		padding: 10rpx 0;
		background: #fff;

		image {
			width: 100%;
			height: 100%;
		}
	}

	/* 秒杀专区 */
	.seckill-section {
		padding: 4rpx 30rpx 24rpx;
		background: #fff;

		.s-header {
			display: flex;
			align-items: center;
			height: 92rpx;
			line-height: 1;

			.s-img {
				width: 140rpx;
				height: 30rpx;
			}

			.tip {
				font-size: $font-base;
				color: $font-color-light;
				margin: 0 20rpx 0 40rpx;
			}

			.timer {
				display: inline-block;
				width: 40rpx;
				height: 36rpx;
				text-align: center;
				line-height: 36rpx;
				margin-right: 14rpx;
				font-size: $font-sm+2rpx;
				color: #fff;
				border-radius: 2px;
				background: rgba(0, 0, 0, .8);
			}

			.icon-you {
				font-size: $font-lg;
				color: $font-color-light;
				flex: 1;
				text-align: right;
			}
		}

		.floor-list {
			white-space: nowrap;
		}

		.scoll-wrapper {
			display: flex;
			align-items: center;
		}

		.floor-item {
			font-size: $font-sm+2rpx;
			color: $font-color-dark;

			image {
				border-radius: 6rpx;
			}

			.price {
				color: $uni-color-primary;
			}
		}
	}

	.f-header {
		display: flex;
		align-items: center;
		height: 140rpx;
		padding: 6rpx 30rpx 8rpx;
		background: #fff;

		image {
			flex-shrink: 0;
			width: 80rpx;
			height: 80rpx;
			margin-right: 20rpx;
		}

		.tit-box {
			flex: 1;
			display: flex;
			flex-direction: column;
		}

		.tit {
			font-size: $font-lg +2rpx;
			color: #font-color-dark;
			line-height: 1.3;
		}

		.tit2 {
			font-size: $font-sm;
			color: $font-color-light;
		}

		.icon-you {
			font-size: $font-lg +2rpx;
			color: $font-color-light;
		}
	}

	/* 团购楼层 */
	.group-section {
		background: #fff;

		.g-swiper {
			height: 650rpx;
			padding-bottom: 30rpx;
		}

		.g-swiper-item {
			width: 100%;
			padding: 0 30rpx;
			display: flex;
		}

		image {
			width: 100%;
			height: 460rpx;
			border-radius: 4px;
		}

		.g-item {
			display: flex;
			flex-direction: column;
			overflow: hidden;
		}

		.left {
			flex: 1.2;
			margin-right: 24rpx;

			.t-box {
				padding-top: 20rpx;
			}
		}

		.right {
			flex: 0.8;
			flex-direction: column-reverse;

			.t-box {
				padding-bottom: 20rpx;
			}
		}

		.t-box {
			height: 160rpx;
			font-size: $font-base+2rpx;
			color: $font-color-dark;
			line-height: 1.6;
		}

		.price {
			color: $uni-color-primary;
		}

		.m-price {
			font-size: $font-sm+2rpx;
			text-decoration: line-through;
			color: $font-color-light;
			margin-left: 8rpx;
		}

		.pro-box {
			display: flex;
			align-items: center;
			margin-top: 10rpx;
			font-size: $font-sm;
			color: $font-base;
			padding-right: 10rpx;
		}

		.progress-box {
			flex: 1;
			border-radius: 10px;
			overflow: hidden;
			margin-right: 8rpx;
		}
	}

	/* 分类推荐楼层 */
	.hot-floor {
		width: 100%;
		overflow: hidden;
		margin-bottom: 20rpx;

		.floor-img-box {
			width: 100%;
			height: 320rpx;
			position: relative;

			&:after {
				content: '';
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
				background: linear-gradient(rgba(255, 255, 255, .06) 30%, #f8f8f8);
			}
		}

		.floor-img {
			width: 100%;
			height: 100%;
		}

		.floor-list {
			white-space: nowrap;
			padding: 20rpx;
			padding-right: 50rpx;
			border-radius: 6rpx;
			margin-top: -140rpx;
			margin-left: 30rpx;
			background: #fff;
			box-shadow: 1px 1px 5px rgba(0, 0, 0, .2);
			position: relative;
			z-index: 1;
		}

		.scoll-wrapper {
			display: flex;
			align-items: flex-start;
		}

		.floor-item {
			width: 180rpx;
			margin-right: 20rpx;
			font-size: $font-sm+2rpx;
			color: $font-color-dark;
			line-height: 1.8;

			image {
				width: 180rpx;
				height: 180rpx;
				border-radius: 6rpx;
			}

			.price {
				color: $uni-color-primary;
			}
		}

		.more {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			flex-shrink: 0;
			width: 180rpx;
			height: 180rpx;
			border-radius: 6rpx;
			background: #f3f3f3;
			font-size: $font-base;
			color: $font-color-light;

			text:first-child {
				margin-bottom: 4rpx;
			}
		}
	}

	/* 猜你喜欢 */
	.guess-section {
		display: flex;
		flex-wrap: wrap;
		padding: 0 30rpx;
		background: #fff;

		.guess-item {
			display: flex;
			flex-direction: column;
			width: 48%;
			padding-bottom: 40rpx;

			&:nth-child(2n+1) {
				margin-right: 4%;
			}
		}

		.image-wrapper {
			width: 100%;
			height: 330rpx;
			border-radius: 3px;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}

		.title {
			font-size: $font-lg;
			color: $font-color-dark;
			line-height: 80rpx;
		}

		.price {
			font-size: $font-lg;
			color: $uni-color-primary;
			line-height: 1;
		}
	}

	.publish-time-view-wrapper {
		display: flex;
		flex-direction: row;
	}

	.demand-type {
		border: 1upx solid #FFD5AB;
		height: 40upx;
		font-size: 24upx;
		line-height: 40upx;
		padding: 0upx 12upx;
		color: #FF9428;
		text-align: center;
		margin-left: 12upx;
		border-radius: 8upx;
	}



	.demand-title {
		font-size: 28upx;
		width: 414upx;
		font-weight: bold;
		color: #191919;
	}

	.nav-title-wrapper {
		width: 100%;
		display: flex;
		flex-direction: row;
		justify-content: center;
		position: relative;

	}

	.nav-title {
		color: #191919;
		font-size: 32upx;
		margin-top: 104upx;
	}

	.demand-status {
		margin-left: 12upx;
		background: #FF4E4C;
		color: #FFFFFF;
		font-size: 24upx;
		height: 32upx;
		line-height: 32upx;
		width: 88upx;
		text-align: center;
		border-radius: 8upx;
		margin-right: 24upx;

	}

	.publish-time-wrapper {
		display: flex;
		margin-top: 20upx;
		flex-direction: row;
		justify-content: space-between;
		margin-left: 24upx;
		margin-bottom: 36upx;
	}

	.home-time-wrapper {
		display: flex;
		height: 40upx;
		width: 180upx;
		text-align: center;
		flex-direction: row;
		border: 1upx solid #FFC9C8;
		border-radius: 8upx;
		align-items: center;
	}

	.time-type-wrapper {
		display: flex;
		flex-direction: row;
		margin-top: 16upx;
		margin-left: 24upx;
	}

	.demand-title-wrapper {
		display: flex;
		flex-direction: row;
		margin-left: 24upx;
		margin-top: 36upx;
		justify-content: space-between;
	}

	.view-count-icon {
		width: 24upx;
		height: 24upx;
	}

	.publish-time-icon {
		width: 24upx;
		height: 24upx;
	}

	.time-icon {
		width: 24upx;
		height: 24upx;
	}

	.demand-wrapper {
		/* margin-top: 40upx; */
		background: #FFFFFF;
		border-radius: 24upx;
		margin-left: 24upx;
		margin-right: 24upx;
		/* padding: 24upx 24upx; */
		display: flex;
		flex-direction: column;
		border-bottom: 2upx solid #F8F8F8;

	}

	.pop-title {
		color: #191919;
		font-size: 24upx;
		margin-top: 16upx;

		align-self: center;
	}

	.pop-window-img {
		align-self: center;

	}

	.desc {
		font-size: 20upx;
		color: #A6A6A6;
		align-self: center;
	}

	.pop-window-in-wrapper {
		display: flex;
		flex-direction: column;
		justify-content: center;

	}

	.pop-window-in-wrapper:nth-child(1) {
		margin-left: 50upx;
	}

	.pop-window-in-wrapper:nth-child(4) {
		margin-right: 50upx;
	}

	/* 	.publish-code{
			 margin-left: 94upx;
		}
		.tech-icon{
			margin-right: 94upx;
		} */
	.pop-window-wrapper {
		margin-top: 24upx;
		display: flex;
		flex-direction: row;
		background: #FFFFFF;
		// width: 702upx;
		margin-left: 24upx;
		margin-right: 24upx;
		height: 180upx;
		border-radius: 24upx;
		justify-content: space-between;
	}

	.pop-window-wrapper image {
		width: 60upx;
		height: 60upx;
	}

	.notify-icon {
		width: 40upx;
		height: 40upx;
		margin-left: 24upx;
	}

	.notify-message {
		margin-left: 12upx;
	}

	.notify-in-wrapper {
		display: flex;
		flex-direction: row;

	}

	.notify-wrapper {
		margin-left: 24upx;
		margin-right: 24upx;
		font-size: 26upx;
		border-radius: 24upx;
		margin-top: 24upx;
		height: 80upx;
		display: flex;
		flex-direction: column;
		justify-content: center;

	}

	.title-banner-wrapper {
		position: relative;
	}




	.nav-title-wrapper {
		width: 100%;
		height: 200upx;
		background: linear-gradient(#FF4E4C, #FF6463);
		display: flex;
		flex-direction: row;
		justify-content: center;
		position: relative;

	}

	.nav-title {
		color: #FFFFFF;
		font-size: 30upx;
		margin-top: 104upx;
	}

	.banner-item {
		width: 100%;
	}

	.banner-wrapper {
		height: 256upx;
		width: 702upx;
		position: absolute;
		margin-top: 176upx;
	}


	swiper-item {
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	swiper-item image {
		border-radius: 24upx;
	}
</style>
